//
//  NetworkingLoadViewManager.m
//  智云网校
//
//  Created by 毕武侠 on 2017/5/22.
//  Copyright © 2017年 bwx. All rights reserved.
//

#import "NetworkingLoadViewManager.h"
#import "LoadView.h"

@interface NetworkingLoadViewManager ()

@property (nonatomic, strong)  LoadView *view;

@end

@implementation NetworkingLoadViewManager
@dynamic view;

- (instancetype)initWithSuperView:(UIView *)view url:(NSString *)url rmodel:(NSString *)rmodel {
    self = [super init];
    if (self) {
        self.superView = view;
        self.url = url;
        self.rmodel = rmodel;
        
        [self setupConfigure];
    }
    return self;
}

- (void)setupConfigure {
    [super setupConfigure];
    
    self.view = [[LoadView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    if (self.superView) {
        [self.superView addSubview:self.view];
    }
    
    [self.view showLoadAnimation];
    @weakify(self)
    [self.receiveSignal subscribeNext:^(id receive) {
        @strongify(self)
        if ([receive isKindOfClass:NSClassFromString(self.rmodel)]) {
            self.view.hidden = YES;
        }
    }];
    // 加载数据失败errors
    [self.errorSignal subscribeNext:^(NSError *error) {
        @strongify(self)
        self.view.loadNoDataText = error.domain;
        [self.view showLoadNoData];
    }];
}

- (void)loadTopViewTitle:(NSString *)title {
    [self.view loadTopTitle:title];
}

- (RACSignal *)backSignal {
    return [self.view getSignalWithDictionary:@{@"action" : @"back"}];
}

@end
